<%--
  Created by IntelliJ IDEA.
  User: LT
  Date: 2018-10-25
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/static/hplus/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/static/hplus/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/hplus/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <link href="${pageContext.request.contextPath}/static/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

    <link href="${pageContext.request.contextPath}/static/hplus/css/animate.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">


    <script>
        //得到查询的参数
        function queryParams (params) {
        };

        $(function () {
            $("#usertb").bootstrapTable({
                url:'${pageContext.request.contextPath}/shangpin/query',
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                //启用服务器端分页
                sidePagination:'server',
                //设置每页多少条数据
                pageSize:15,
                pageList:[2,4,8,16],
                height:550,
                clickToSelect:true,
                singleSelect:true,
                pageNumber:1,
                //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果 queryParamsType = 'limit' ,返回参数必须包含
                //limit, offset, search, sort, order 否则, 需要包含:
                //pageSize, pageNumber, searchText, sortName, sortOrder.
                // 返回false将会终止请求。
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        username:$("#username").val()
                    };
                    return temp;
                },
                columns:[
                    {
                        checkbox:true,
                    },
                    {
                        field:'sid',
                        title:'编号',
                    },
                    {
                        field:'sname',
                        title:'名称'
                    },
                    {
                        field:'scount',
                        title:'库存量'
                    },
                    {
                        field:'xid',
                        title:'类别',
                        formatter (value, row, index, field){
                            if (row.xid == 1) {
                                return "水果";
                            }else if(row.xid == 2){
                                return "海鲜";
                            }else if(row.xid == 3){
                                return "肉类";
                            }else if(row.xid == 4){
                                return "饼干";
                            }else if(row.xid == 5){
                                return "牛奶";
                            }else if(row.xid == 6){
                                return "薯片";
                            }else if(row.xid == 7){
                                return "洗发水";
                            }else if(row.xid == 8){
                                return "沐浴露";
                            }else if(row.xid == 9){
                                return "洗面奶";
                            }else if(row.xid == 10){
                                return "大米";
                            }else if(row.xid == 11){
                                return "调料";
                            }else if(row.xid == 12){
                                return "油";
                            }else if(row.xid == 13){
                                return "洗衣液";
                            }else if(row.xid == 14){
                                return "洗衣灵";
                            }else if(row.xid == 15){
                                return "纸";
                            }
                        }

                    },
                    {
                        field:'chengben',
                        title:'成本价'
                    },
                    {
                        field:'danjia',
                        title:'单价'
                    },
                    {
                        field:'dwid',
                        title:'规格',
                        formatter (value, row, index, field){
                            if (row.dwid == 1) {
                                return "斤";
                            }else if(row.dwid == 2){
                                return "个";
                            }else if(row.dwid == 3){
                                return "盒";
                            }else if(row.dwid == 4){
                                return "桶";
                            }else if(row.dwid == 5){
                                return "箱";
                            }else if(row.dwid == 6){
                                return "袋";
                            }else if(row.dwid == 7){
                                return "瓶";
                            }
                        }
                    },



                ]
            }) ;
        }) ;



        function searcha() {
            var opts = $("#usertb").bootstrapTable("getOptions") ;
            var limit = opts.pageSize ;
            var offset = (opts.pageNumber-1) * limit;
            var username = $("#username").val() ;
            $.post("${pageContext.request.contextPath}/shangpin/query",{'sname':username,'limit':limit,'offset':offset},function (data) {
                // var mydata = eval("("+data+")") ;
                //重新绑定表格数据
                $("#usertb").bootstrapTable('load',data) ;
            })
        }


        function del(){
            var myrows =  $("#usertb").bootstrapTable("getSelections") ;
            if(myrows.length==0){
                alert("请选中要添加的商品!") ;

            }
            else{
                //得到选中行的主键
                $("[name=shuliang]").val(1);
                id = myrows[0].sid ;
                $("#div1").modal("show") ;

                $.post('${pageContext.request.contextPath}/jinhuols/delet',{'id':id},function(data){

                })


            }

        }


        function tofenpei(){
            var myrows =  $("#usertb").bootstrapTable("getSelections") ;
            if(myrows.length==0){
                alert("请选中要添加的商品!") ;

            }
            else{
                //得到选中行的主键
                $("[name=shuliang]").val(1);
                id = myrows[0].sid ;
                $("#div1").modal("show") ;

                $.post('${pageContext.request.contextPath}/shangpin/getsid',{'sid':id},function(data){
                    $("#Div2").modal('show');
                    //绑定事件
                    $("#Div2").on('shown.bs.modal',function(e){
                        //给表单赋值
                        $("[name=sid]").val(data.sid);
                        $("[name=sname]").val(data.sname);
                        $("[name=scount]").val(data.scount);
                        $("[name=danjia]").val(data.chengben);
                        $("[name=chengben]").val(data.danjia);
                        $("[name=xid]").val(data.xid);
                        $("[name=dwid]").val(data.dwid);
                    })
                })


            }

        }





        function newNnb() {
            var num = $("#juesebody3 input[name=shuliang]").val();
            var tos = $("#juesebody4 input[name=danjia]").val();
            $("#juesebody5 input[name=danjia]").val((parseFloat(tos) * parseInt(num)).toFixed(1));
        }






        function doadd(){
            var huoid=$("#sid").val();
            var huoname=$("#sname").val();
            var huodan=$("#dwid").val();
            var huolei=$("#xid").val();
            var huoshu=$("#danjia").val();
            var huodanjia=$("#shuliang").val();
            var huozongjia=$("#zongjia").val();

            $.post('${pageContext.request.contextPath}/jinhuols/addls',{"huoid":huoid,'huoname':huoname,'huodan':huodan,'huolei':huolei,'huoshu':huodanjia,'huodanjia':huoshu,'huozongjia':huozongjia},function(data){
                if(data>0){
                    // var mydata = eval("("+data+")") ;
                    //重新绑定表格数据
                    $("#Div2").modal('hide');
                    alert("添加成功") ;
                }
            });

        }
    </script>

    <script>
    </script>




</head>



<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4" >
        <h2>采购进货</h2>
        <ol class="breadcrumb">

        </ol>
    </div>

</div>

<div class="wrapper wrapper-content" style="background: #EDF2F8">
    <div class="row">
          <%--  <div class="col-md-1" style="width:200px ;margin-left:100px;height:50px" >
                <span class="input-group-addon" id="basic-addon3">供货商</span>
                <input type="text" style="height:35px" class="form-control" id="basic-url" aria-describedby="basic-addon3">
            </div>--%>
            <%--<div class="col-md-1" style="width:200px ;margin-left:150px;height:50px" >
                <span class="input-group-addon" >收货仓库</span>
                <select class="form-control m-b" name="account">
                    <option>选项 1</option>
                    <option>选项 2</option>
                    <option>选项 3</option>
                    <option>选项 4</option>
                </select>
            </div>--%>



<%--
        <div class="col-md-1"style="margin-left:0px; margin-top: -15px">
            <div class="title-action">
                <a href="" class="btn btn-primary">删除商品</a>
            </div>
        </div>--%>

        <div class="col-md-1"style="margin-left:0px; margin-top: -15px">
            <div class="title-action">

                <input id="username" type="text" class="form-control">
            </div>
        </div>


        <div class="col-md-1"style="margin-left:0px; margin-top: 15px">

            <button onclick='searcha()' class="btn btn-primary">查询</button>

        </div>

              <div class="col-md-1"style="margin-left:0px; margin-top: -15px">
                  <div class="title-action">
                      <button onclick='tofenpei()' class="btn btn-success btn-sm demo2">添加商品</button>
                  </div>
              </div>

    </div>
</div>


<div class="panel panel-default">

    <div class="panel-body" <%--style="width:850px;height:850px"--%>>

        <table id="usertb"></table>

    </div>
</div>







<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" id="Div2">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" >采购进货</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>商品名称:</h2></label>
                    <div class="col-sm-10" id="juesebody" style="margin-top: 15px">
                        <input style="color: #010101" name="sname" id="sname" type="text" readOnly="true" class="form-control">
                        <input style="color: #010101" name="sid" id="sid"  type="hidden"  readOnly="true" class="form-control">
                        <input style="color: #010101" name="xid"  id="xid" type="hidden"  readOnly="true" class="form-control">
                        <input  name="dwid" id="dwid" type="hidden"  readOnly="true" class="form-control">
                    </div>
                </div>
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>库存量:</h2></label>
                    <div class="col-md-4" id="juesebody1" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px"name="scount" id="scount" type="text" readOnly="true" class="form-control">
                    </div>
                    <label class="col-sm-2 control-label"><h2>单价:</h2></label>
                    <div class="col-md-4" id="juesebody2" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px"name="chengben" id="chengben" type="text" readOnly="true" class="form-control">
                    </div>
                </div>
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>成本:</h2></label>
                    <div class="col-md-4" id="juesebody4" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px"name="danjia" id="danjia"  readOnly="true"   type="text" onkeyup="newNnb()"  class="form-control">
                    </div>
                    <label class="col-sm-2 control-label"><h2>数量:</h2></label>
                    <div class="col-md-4" id="juesebody3" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 80px" name="shuliang" id="shuliang" onkeyup="newNnb()" value="1" type="text" class="form-control">
                    </div>
                </div>
                <div class="row">
                    <label class="col-sm-2 control-label"><h2>商品总价:</h2></label>
                    <div class="col-md-4" id="juesebody5" style="margin-top: 15px">
                        <input style="color: #010101 ;width: 150px"name="danjia" id="zongjia" readOnly="true" type="text"  class="form-control">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button onclick="doadd()" type="button" class="btn btn-primary">添加</button>
            </div>
        </div>
    </div>
</div>


<div class="col-sm-6 h-100 p-lg">
    <p>成功提示 </p>
    <button class="btn btn-success btn-sm demo2">打开示例</button>
</div>
</body>

</html>

